import { Component } from "react";
import Script from "react-load-script";

export default class Lived2d extends Component {
  constructor(props) {
    super(props);
    this.state = {
      isShow: this.props.isShow,
    };
    if (this.state.isShow) {
      console.log("动画娘：已开启");
    }
  }
  handleScriptCreate() {
    this.setState({ scriptLoaded: false });
  }

  handleScriptError() {
    console.log("动画娘加载失败");
  }

  handleScriptLoad() {
    console.log("动画娘加载完成");
  }
  render() {
    if (this.state.isShow) {
      return (
        <div>
          <Script
            url="/js/live2d.js"
            onCreate={this.handleScriptCreate.bind(this)}
            onError={this.handleScriptError.bind(this)}
            onLoad={this.handleScriptLoad.bind(this)}
          ></Script>
        </div>
      );
    } else {
      return <div></div>;
    }
  }
}
